import { ArticleModel } from "@/database";

/**
 * 文章详情
 * @url /api/v1/article/getArticleInfo
 * @method GET
 */
export default defineEventHandler(async (event) => {
    const { id } = getQuery<{ id: string }>(event)
    if (!id) {
        return failApi('id不能为空')
    }

    const row = ArticleModel.find((item) => item.id.toString() === id)
    if (!row) {
        return failApi('找不到文章')
    }
    const row_last = ArticleModel.find((item) => item.id === row.id - 1)
    const row_next = ArticleModel.find((item) => item.id === row.id + 1)
    return successApi('请求成功', {
        row,
        row_last,
        row_next,
    })
})